{extend name="layout/tpl" /}
{block name="title"}{$title ?? ''}{/block}
{block name="css"}
{__block__}
<style type="text/css">
	body{overflow: hidden;}
	.layui-col-sm20{
		width:20%;
		float: left;
	}
	h3{font-weight: 700;
		text-align: center;}
	.newListTableBg{    margin-top: 5px;}
	.newCommonListStyle{
		width:100%;
		margin-left: 0;
		margin-right: 0;
	}
	.newCommonListStyle .newListTableBg {
		padding-left: 0;
		padding-right: 0;
	}
	#list{width: 100%;text-align: left;}
	#list th{
		padding: 15px 15px 15px 0;
		font-size: 16px;
	}
	#list div.line{margin-bottom: 20px;}
	#list .team{margin-left: 15px;}
	#list .team a{color: #666666;}
	#list .match_time{font-weight: bold;}
	#list .score{font-weight: bold;}
	#list .score-gray{color: gray;}
	#list .score-red{color: #ff3d3d;}
	#list .score-brown{color: brown;}
	#list .score-blue{color: blue;}
	#list .score-green{color: #229c1d;}
	#list .date{padding: 5px;}

	.team-list{min-height: 850px;}
	.active{ color: #ec4fff!important;font-weight: 700; }
</style>
{/block}
{block name="content"}
{__block__}
<div class="newCommonListStyle">

	<div class="weadmin-body layui-fluid" style="display: none;" >
		<form class="layui-form" action="">
			<?php  echo \app\common\utils\Form::hidden('type',$type ?? 0,['id'=>'type']); ?>

			<div class="fixedTop">
				<div class="layui-form layui-card-header layuiadmin-card-header-auto layui-card-more" id="select-form">
					<i class="more-btn">更多筛选条件</i>
					<div class="boxContain">
						<button class="layui-btn select_form search-btn" title="查询" lay-submit lay-filter="submit"  data-type="search" data-toggle="tooltip">查询</button>
						<button class="layui-btn layui-btn-primary clearBtn" type="button" >清空条件</button>
						<button type="button" class="layui-btn" onclick="WeAdminShow('批量添加','{$mnBatchAddUrl }')">批量添加</button>
						<button type="button" class="layui-btn" onclick="javascript:setMatch();">更新比赛</button>

					</div>
					<div class="layui-form-item all-search" show_type="2" >
						<div class="layui-inline">
							<?php  echo \app\common\utils\Form::label('match_time','比赛日期',['class'=>'layui-form-label layui-form-label-n','is_on'=>'0']); ?>
							<div class="layui-input-block layui-input-block-n">
								<?php  echo \app\common\utils\Form::text('match_time', input('match_time',date('Y-m-d H:i:s',time() - 60 * 30) . ' ~ ' .date('Y-m-d 23:59:59',strtotime('+2 day'))),['placeholder'=>'比赛日期','id'=>'match_time','autocomplete'=>'off','class'=>'layui-input']); ?>
							</div>
						</div>

						<div class='layui-inline'>
							<?php  echo \app\common\utils\Form::label('country_id','所属地区',['class'=>'layui-form-label','is_on'=>'0']); ?>
							<div class="layui-input-block layui-input-block-n">
								<div id="country_id" class=""></div>
							</div>
						</div>

						<div class="layui-inline">
							<?php  echo \app\common\utils\Form::label('team','球队名称',['class'=>'layui-form-label layui-form-label-n','is_on'=>'0']); ?>
							<div class="layui-input-block layui-input-block-n">
								<?php  echo \app\common\utils\Form::text('team','',['placeholder'=>'球队名称','id'=>'team','autocomplete'=>'off','class'=>'layui-input']); ?>
							</div>
						</div>

						<div class='layui-inline'>
							<?php  echo \app\common\utils\Form::label('team_id','球队',['class'=>'layui-form-label','is_on'=>'0']); ?>
							<div class="layui-input-block layui-input-block-n">
								<div id="team_id" class=""></div>
							</div>
						</div>

						<div class='layui-inline'>
							<?php  echo \app\common\utils\Form::label('main_team_id','主队',['class'=>'layui-form-label','is_on'=>'0']); ?>
							<div class="layui-input-block layui-input-block-n">
								<div id="main_team_id" class=""></div>
							</div>
						</div>

						<div class='layui-inline'>
							<?php  echo \app\common\utils\Form::label('visiting_team_id','客队',['class'=>'layui-form-label','is_on'=>'0']); ?>
							<div class="layui-input-block layui-input-block-n">
								<div id="visiting_team_id" class=""></div>
							</div>
						</div>

						<div class='layui-inline'>
							<?php  echo \app\common\utils\Form::label('club_id','所属俱乐部',['class'=>'layui-form-label','is_on'=>'0']); ?>
							<div class="layui-input-block layui-input-block-n">
								<div id="club_id" class=""></div>
							</div>
						</div>

					</div>
				</div>
			</div>
		</form>
		<div class="clear"></div>
	</div>



	<div class="newListTableBg"  style="width: auto;">
		<div class="team-list l-dev" style="width: 24%;float: left;">
			<table id="list">
				<tbody></tbody>
			</table>
		</div>
		<div class="team-list r-dev" style="width: 75%;float: right;">
			<iframe src="" frameborder="0"  id="team-main" class="team-list" style="min-width: 100%"></iframe>
		</div>
	</div>

</div>


{/block}

{block name="footerjs"}
{__block__}
<script src="/static/js/score.js?v={$version}"></script>
<script>
	var team_id = '{:input("team_id") }';
	getList = function () {
		var form = layui.form;
		var laypage = layui.laypage //分页
				,table = layui.table //表格
				,laydate = layui.laydate//日期
				,$ = layui.$
		;
		laydate.render({
			elem: '#match_time_start'
		});
		laydate.render({
			elem: '#match_time_end'
		});

		laydate.render({
			elem: '#match_time'
			,type: 'datetime'
			,range: '~'
		});

		//执行一个 table 实例
		var param = arrayToObject($('form').serializeArray());
		param['per_page'] = 2000;
		param['list_formate'] = 2;
		if( param['match_time'] == '' &&  '{:input("match_time") }' ) param['match_time'] = '{:input("match_time") }';
		if(( typeof param['main_team_id'] == "undefined" || param['team_id'] == '') &&  '{:input("team_id") }' ) param['team_id'] = '{:input("team_id") }';
		if( ( typeof param['main_team_id'] == "undefined" || param['main_team_id'] == '' ) &&  '{:input("main_team_id") }' ) param['main_team_id'] = '{:input("main_team_id") }';
		if( param['visiting_team_id'] == '' &&  '{:input("visiting_team_id") }' ) param['visiting_team_id'] = '{:input("visiting_team_id") }';

		var url = '{$mnIndexUrl}', noticeDetailUrl = '';
		var index;
		$.ajax({
			type:    'post',
			url:     url,
			data:    param,
			dataType:'json',
			beforeSend:function () {
				index = layer.load(0, {shade: false});
			},
			success:    function (result) {
				layer.close(index);
				var data = result.data.list;
				var html = '',beginIndex = 1;
				for(var d in data){
					html += '<tr>';
					// html += '<td><span class="date">' + d + '</span></td>';

					for(var j in data[d]){
						if(beginIndex == 1){ html += '<td valign="top" style="padding-left: 15px;">'; } else { html += '<td valign="top" >'; };
						if( typeof data[d][j] != 'undefined'){
							for(var i in data[d][j]){
								var item = data[d][j];

								noticeDetailUrl = '/Analyse/detail?match_time=&main_team_id=' + item[i].main_team_id +'&visiting_team_id=' + item[i].visiting_team_id  + '&title=' + item[i].main_team + '~' + item[i].visiting_team;

								html += '<div class="line">';
								html += '<div><em class="match_time">' + item[i].match_time + '</em>';
								html += '<span class="team">' +
										'<a id="notice_detail_' + i + '"  onclick="javastript:showNoticeDetail(this);" style="cursor: pointer;" url="' + noticeDetailUrl  +'">' + item[i].main_team + ' ~ ' + item[i].visiting_team + '</a>' +
										'</span>' +
										'</div>';

								html += '</div>';
							}
						}
						html += '</td>';
					}
					html += '</tr>';
					html += '<tr><td colspan="10"><hr /></td></tr>';

					beginIndex = 1;
				}
				;
				$('#list>tbody').html(html);
				$('#notice_detail_0').click();
				// $('#team-main').attr('src',noticeDetailUrl);
			}
		});

	}

	layui.use(['laypage','table','form','laydate','soulTable'], function () {
		var form = layui.form
				,laypage = layui.laypage //分页
				,table = layui.table //表格
				,laydate = layui.laydate//日期
				,$ = layui.$
		;
		if(typeof getList == 'function') getList();
		form.on('submit(submit)',function(data){
			getList();
			return false;   // 阻止表单跳转
		});
	});

	if(typeof getTeams != "function") {
		/**
		 * 获取球队列表
		 * @param item_name
		 * @param id
		 * @param url
		 */
		getTeams = function () {
			var id = '{:input("team_id") }',main_team_id = '{:input("main_team_id") }',visiting_team_id = '{:input("visiting_team_id") }';
			var ids = (id != '') ? id.split(',') : [];
			var main_ids = (main_team_id != '') ? main_team_id.split(',') : [];
			var visiting_ids = (visiting_team_id != '') ? visiting_team_id.split(',') : [];
			var url = "{$selectTeamUrl}";
			layui.use(['layer','form','jquery','xmSelect',], function () {
				layui.form.render();
				var xmSelectObj = xmSelect.render({
					el: '#team_id',
					toolbar: {show: true},
					filterable: true,
					name:'team_id',
					prop:{
						name : 'name',
						value : 'id',
					},
					initValue: ids,
					data: []
				});

				var xmSelectMainObj = xmSelect.render({
					el: '#main_team_id',
					toolbar: {show: true},
					filterable: true,
					name:'main_team_id',
					prop:{
						name : 'name',
						value : 'id',
					},
					initValue: main_ids,
					data: []
				});

				var xmSelectVisitObj = xmSelect.render({
					el: '#visiting_team_id',
					toolbar: {show: true},
					filterable: true,
					name:'visiting_team_id',
					prop:{
						name : 'name',
						value : 'id',
					},
					initValue: visiting_ids,
					data: []
				});

				$.ajax({
					type:    'post',
					url:     url,
					data:    {
						type: $('#type').val(),
						name: '',
						page: 1,
						is_get_all:1,
					},
					dataType:'json',
					beforeSend:function () {
						//index = layer.load(0, {shade: false});
					},
					success:    function (result) {
						xmSelectObj.update({
							data: result.data,
						})
						xmSelectMainObj.update({
							data: result.data,
						})
						xmSelectVisitObj.update({
							data: result.data,
						})
						//layer.close(index);
					},
					complete: function () {
						layui.form.render();
					}
				});
			});
		}
	}

	if(typeof getClub != "function") {
		/**
		 * 获取列表
		 * @param item_name
		 * @param id
		 * @param url
		 */
		getClub = function (name,id) {
			var ids = (id != '') ? id.split(',') : [];
			var url = "{$selectClubUrl}";
			layui.use(['layer','form','jquery','xmSelect',], function () {
				layui.form.render();
				var xmSelectObj = xmSelect.render({
					el: '#club_id',
					toolbar: {show: true},
					filterable: true,
					name:'club_id',
					prop:{
						name : 'name',
						value : 'id',
					},
					initValue: ids,
					data: []
				});

				$.ajax({
					type:    'post',
					url:     url,
					data:    {
						type: $('#type').val(),
						name: name,
						page: 1,
						is_get_all:1,
					},
					dataType:'json',
					beforeSend:function () {
						//index = layer.load(0, {shade: false});
					},
					success:    function (result) {
						xmSelectObj.update({
							data: result.data,
						})
						//layer.close(index);
					},
					complete: function () {
						layui.form.render();
					}
				});
			});
		}
	}

	if(typeof getCountry != "function") {
		/**
		 * 获取列表
		 * @param item_name
		 * @param id
		 * @param url
		 */
		getCountry = function (id) {
			var ids = (id != '') ? id.split(',') : [];
			layui.use(['layer','form','jquery','xmSelect',], function () {
				layui.form.render();
				var xmSelectObj = xmSelect.render({
					el: '#country_id',
					toolbar: {show: true},
					filterable: true,
					name:'country_id',
					prop:{
						name : 'name',
						value : 'id',
					},
					initValue: ids,
					data: []
				});
				var json = {:json_encode($country_array)};
				var data = [];
				for(var i in json) data.push({id:i,name:json[i]});
				xmSelectObj.update({
					data: data,
				})

			});
		}
	}

	if(typeof setMatch != "function") {
		/**
		 * 获取列表
		 * @param item_name
		 * @param id
		 * @param url
		 */
		setMatch = function () {
			var index;
			var param = arrayToObject($('form').serializeArray());
			$.ajax({
				type:       'post',
				url:       '{$snycMatchUrl}',
				data:       param,
				dataType:   'json',
				beforeSend: function () {
					index = layer.load(0, {shade: [0.2, '#393D49']});
				},
				success:    function (result) {
					console.log('result',result)
					layer.close(index);
					if(result.code == 1) {
						var msg = '数据总数【'+ result.data.total + '】条，成功处理【'+ result.data.success  + '】条';
						layer.msg(msg);
						$('button[data-type="search"]').click();
					} else {
						layer.msg(result.msg,{icon: 5});
					}
				}
			});
		}
	}

	showNoticeDetail = function(that){
		var url = $(that).attr('url');
		$('#team-main').attr('src',url);
		$('.team a').removeClass('active');
		$(that).addClass('active');
	}

	$(document).ready(function () {
		getTeams();
		getClub("","{:input('club_id') }");
		getCountry("{:input('country_id') }");
	});
	//回车进行搜索
	$(document).keydown(function(event){
		if(event.keyCode==13){
			$('button[data-type="search"]').click();
		}
	});

</script>
{/block}
